package com.zmt.content.api;

import com.zmt.content.dto.CourseBaseInfoDto;
import com.zmt.content.dto.CoursePreviewDto;
import com.zmt.content.dto.TeachplanDto;
import com.zmt.content.service.CourseBaseService;
import com.zmt.content.service.TeachPlanService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(value = "课程公开查询接口",tags = "课程公开查询接口")
@RestController
@RequestMapping("/open")
public class CourseOpenController {

    @Autowired
    private CourseBaseService courseBaseService;

    @Autowired
    private TeachPlanService teachPlanService;

    /**
     * 获取课程信息（用于展示在视频播放时的目录位置）
     * @return
     */
    @GetMapping("/course/whole/{courseId}")
    public CoursePreviewDto getCourseBaseInfo(@PathVariable("courseId") Long courseId){
        CoursePreviewDto coursePreviewDto = new CoursePreviewDto();
        CourseBaseInfoDto courseBaseInfo = courseBaseService.getCourseBaseInfo(courseId);
        List<TeachplanDto> teachplanDtos = teachPlanService.selectTreeNodes(courseId);

        coursePreviewDto.setTeachplans(teachplanDtos);
        coursePreviewDto.setCourseBase(courseBaseInfo);
        return coursePreviewDto;
    }
}

